//
//  HLAccostContentView.m
//  YueYue
//
//  Created by hulu001 on 2023/6/12.
//

#import "HLAccostContentView.h"
#import <FrameAccessor/FrameAccessor.h>
#import <NIMSDK/NIMSDK.h>
#import "HLIMKitMessageModel.h"
#import "HLAccostAttachment.h"

@implementation HLAccostContentView


- (instancetype)init
{
    self = [super init];
    if (self) {
        self.bubbleImageView.hidden = YES;
        self.backgroundColor = UIColor.whiteColor;
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = YES;
        
        self.giftImageView = [UIImageView.alloc init];
        [self addSubview:self.giftImageView];
        
        self.line = [UIView.alloc init];
        self.line.backgroundColor = [UIColor colorWithRed:240/255.0 green:242/255.0 blue:245/255.0 alpha:0.5];
        [self addSubview:self.line];
        
        self.contentLabel = [UILabel.alloc init];
        self.contentLabel.textColor = [UIColor colorWithRed:36/255.0 green:41/255.0 blue:51/255.0 alpha:1.0];
        self.contentLabel.font = [UIFont systemFontOfSize:12];
        self.contentLabel.numberOfLines = 0;
        [self addSubview:self.contentLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.giftImageView.frame = CGRectMake(12, 4, self.width - 24, 60);
    
    self.line.frame = CGRectMake(12, self.giftImageView.bottom + 4, self.width - 24, 0.5);
    
    self.contentLabel.frame = CGRectMake(12, 76, self.width - 24, self.height - 76 - 8);
}

- (void)refreshData:(HLIMKitMessageModel *)messageModel
{
    [super refreshData:messageModel];
    
    NIMCustomObject *object = (NIMCustomObject *)messageModel.message.messageObject;
    HLAccostAttachment *attachment = (HLAccostAttachment *)object.attachment;
    
    self.contentLabel.text = attachment.chatUpMsg;
    [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:attachment.imgUrl] placeholderImage:[UIImage imageNamed:@"imImagePlaceholder"]];
}

@end
